package chpt05;

interface ICalculate {
	public double add(double x, double y);
}

public class AnonymousTest {
	public static void main(String[] args) {
		// 父类类型是Car的匿名内部类
		Car y = new Car() {
			{System.out.println("匿名类内可以有初始化块");}
			@Override
			public String toString() {
				return "父类类型：" + getClass().getSuperclass() + 
						"。 匿名类类型：" + getClass();
			}
		};
		System.out.println(y);
		// 实现了接口的匿名类
		ICalculate calculator = new ICalculate() {
			@Override
			public double add(double x, double y) {
				return x + y;
			}
		};
		System.out.println(calculator instanceof ICalculate);
		System.out.println(calculator.add(1, 2));
	}
}
